package com.meihua.shellapp.activity.wallet;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.bean.WithdrawalDetailBean;
import com.meihua.shellapp.databean.WithdrawalDetailDataBean;
import com.meihua.shellapp.utils.DateUtils;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;


/**
 * 我的钱包--提现详情界面
 */
public class WithdrawalsDetailActivity extends BaseActivity {

    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.iv_top_left)
    ImageView mIVTopLeft;

    @Bind(R.id.tv_time)
    TextView tv_time;//时间
    @Bind(R.id.tv_money)
    TextView tv_money;//金额
    @Bind(R.id.tv_account)
    TextView tv_account;//帐号

    private String id;

    @Override
    public int getLayoutId() {
        return R.layout.activity_withdrawals_details;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        id = getIntent().getStringExtra("id");
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText("提现详情");
        mIVTopLeft.setVisibility(View.VISIBLE);
        mIVTopLeft.setOnClickListener(this);
    }

    private void bindData(WithdrawalDetailDataBean data) {
        tv_time.setText(DateUtils.getInstance().getTimeYMDHM(data.getTime()));
        tv_money.setText(data.getMoney());
        tv_account.setText(data.getAccount_number());
    }

    @Override
    public void createLoadData() {
        super.createLoadData();
        OkGo.<String>post(URL.getUrl().GETWITHDRAWETAIL)
                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        WithdrawalDetailBean bean = MyApplication.getInstance().getBeanForJson(WithdrawalDetailBean.class, response.body());
                        if (bean == null) {
                            return;
                        }
                        if (bean.getCode() == 1) {
                            bindData(bean.getData());
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });
    }

}
